home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / TTY.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  14KB  |  410 lines

  1. #ifndef _LINUX_TTY_H
  2. #define _LINUX_TTY_H
  3.  
  4. /*
  5.  * 'tty.h' defines some structures used by tty_io.c and some defines.
  6.  */
  7.  
  8. /*
  9.  * These constants are also useful for user-level apps (e.g., VC
  10.  * resizing).
  11.  */
  12. #define MIN_NR_CONSOLES 1       /* must be at least 1 */
  13. #define MAX_NR_CONSOLES    63    /* serial lines start at 64 */
  14. #define MAX_NR_USER_CONSOLES 63    /* must be root to allocate above this */
  15.         /* Note: the ioctl VT_GETSTATE does not work for
  16.            consoles 16 and higher (since it returns a short) */
  17.  
  18. #ifdef __KERNEL__
  19. #include <linux/config.h>
  20. #include <linux/fs.h>
  21. #include <linux/major.h>
  22. #include <linux/termios.h>
  23. #include <linux/tqueue.h>
  24. #include <linux/tty_driver.h>
  25. #include <linux/tty_ldisc.h>
  26. #include <linux/serialP.h>
  27.  
  28. #include <asm/system.h>
  29.  
  30.  
  31. /*
  32.  * Note: don't mess with NR_PTYS until you understand the tty minor 
  33.  * number allocation game...
  34.  * (Note: the *_driver.minor_start values 1, 64, 128, 192 are
  35.  * hardcoded at present.)
  36.  */
  37. #define NR_PTYS        256    /* ptys/major */
  38. #define NR_LDISCS    16
  39.  
  40. /*
  41.  * Unix98 PTY's can be defined as any multiple of NR_PTYS up to
  42.  * UNIX98_PTY_MAJOR_COUNT; this section defines what we need from the
  43.  * config options
  44.  */
  45. #ifdef CONFIG_UNIX98_PTYS
  46. # define UNIX98_NR_MAJORS ((CONFIG_UNIX98_PTY_COUNT+NR_PTYS-1)/NR_PTYS)
  47. # if UNIX98_NR_MAJORS <= 0
  48. #  undef CONFIG_UNIX98_PTYS
  49. # elif UNIX98_NR_MAJORS > UNIX98_PTY_MAJOR_COUNT
  50. #  error  Too many Unix98 ptys defined
  51. #  undef  UNIX98_NR_MAJORS
  52. #  define UNIX98_NR_MAJORS UNIX98_PTY_MAJOR_COUNT
  53. # endif
  54. #endif
  55.  
  56. /*
  57.  * These are set up by the setup-routine at boot-time:
  58.  */
  59.  
  60. struct screen_info {
  61.     unsigned char  orig_x;            /* 0x00 */
  62.     unsigned char  orig_y;            /* 0x01 */
  63.     unsigned short dontuse1;        /* 0x02 -- EXT_MEM_K sits here */
  64.     unsigned short orig_video_page;        /* 0x04 */
  65.     unsigned char  orig_video_mode;        /* 0x06 */
  66.     unsigned char  orig_video_cols;        /* 0x07 */
  67.     unsigned short unused2;            /* 0x08 */
  68.     unsigned short orig_video_ega_bx;    /* 0x0a */
  69.     unsigned short unused3;            /* 0x0c */
  70.     unsigned char  orig_video_lines;    /* 0x0e */
  71.     unsigned char  orig_video_isVGA;    /* 0x0f */
  72.     unsigned short orig_video_points;    /* 0x10 */
  73.  
  74.     /* VESA graphic mode -- linear frame buffer */
  75.     unsigned short lfb_width;        /* 0x12 */
  76.     unsigned short lfb_height;        /* 0x14 */
  77.     unsigned short lfb_depth;        /* 0x16 */
  78.     unsigned long  lfb_base;        /* 0x18 */
  79.     unsigned long  lfb_size;        /* 0x1c */
  80.     unsigned short dontuse2, dontuse3;    /* 0x20 -- CL_MAGIC and CL_OFFSET here */
  81.     unsigned short lfb_linelength;        /* 0x24 */
  82.     unsigned char  red_size;        /* 0x26 */
  83.     unsigned char  red_pos;            /* 0x27 */
  84.     unsigned char  green_size;        /* 0x28 */
  85.     unsigned char  green_pos;        /* 0x29 */
  86.     unsigned char  blue_size;        /* 0x2a */
  87.     unsigned char  blue_pos;        /* 0x2b */
  88.     unsigned char  rsvd_size;        /* 0x2c */
  89.     unsigned char  rsvd_pos;        /* 0x2d */
  90.     unsigned short vesapm_seg;        /* 0x2e */
  91.     unsigned short vesapm_off;        /* 0x30 */
  92.     unsigned short pages;            /* 0x32 */
  93.                         /* 0x34 -- 0x3f reserved for future expansion */
  94. };
  95.  
  96. extern struct screen_info screen_info;
  97.  
  98. #define ORIG_X            (screen_info.orig_x)
  99. #define ORIG_Y            (screen_info.orig_y)
  100. #define ORIG_VIDEO_MODE        (screen_info.orig_video_mode)
  101. #define ORIG_VIDEO_COLS     (screen_info.orig_video_cols)
  102. #define ORIG_VIDEO_EGA_BX    (screen_info.orig_video_ega_bx)
  103. #define ORIG_VIDEO_LINES    (screen_info.orig_video_lines)
  104. #define ORIG_VIDEO_ISVGA    (screen_info.orig_video_isVGA)
  105. #define ORIG_VIDEO_POINTS       (screen_info.orig_video_points)
  106.  
  107. #define VIDEO_TYPE_MDA        0x10    /* Monochrome Text Display    */
  108. #define VIDEO_TYPE_CGA        0x11    /* CGA Display             */
  109. #define VIDEO_TYPE_EGAM        0x20    /* EGA/VGA in Monochrome Mode    */
  110. #define VIDEO_TYPE_EGAC        0x21    /* EGA in Color Mode        */
  111. #define VIDEO_TYPE_VGAC        0x22    /* VGA+ in Color Mode        */
  112. #define VIDEO_TYPE_VLFB        0x23    /* VESA VGA in graphic mode        */
  113.  
  114. #define VIDEO_TYPE_TGAC        0x40    /* DEC TGA */
  115.  
  116. #define VIDEO_TYPE_SUN          0x50    /* Sun frame buffer. */
  117. #define VIDEO_TYPE_SUNPCI       0x51    /* Sun PCI based frame buffer. */
  118.  
  119. #define VIDEO_TYPE_PMAC        0x60    /* PowerMacintosh frame buffer. */
  120.  
  121. /*
  122.  * This character is the same as _POSIX_VDISABLE: it cannot be used as
  123.  * a c_cc[] character, but indicates that a particular special character
  124.  * isn't in use (eg VINTR has no character etc)
  125.  */
  126. #define __DISABLED_CHAR '\0'
  127.  
  128. /*
  129.  * This is the flip buffer used for the tty driver.  The buffer is
  130.  * located in the tty structure, and is used as a high speed interface
  131.  * between the tty driver and the tty line discipline.
  132.  */
  133. #define TTY_FLIPBUF_SIZE 512
  134.  
  135. struct tty_flip_buffer {
  136.     struct tq_struct tqueue;
  137.     struct semaphore pty_sem;
  138.     char        *char_buf_ptr;
  139.     unsigned char    *flag_buf_ptr;
  140.     int        count;
  141.     int        buf_num;
  142.     unsigned char    char_buf[2*TTY_FLIPBUF_SIZE];
  143.     char        flag_buf[2*TTY_FLIPBUF_SIZE];
  144.     unsigned char    slop[4]; /* N.B. bug overwrites buffer by 1 */
  145. };
  146. /*
  147.  * The pty uses char_buf and flag_buf as a contiguous buffer
  148.  */
  149. #define PTY_BUF_SIZE    4*TTY_FLIPBUF_SIZE
  150.  
  151. /*
  152.  * When a break, frame error, or parity error happens, these codes are
  153.  * stuffed into the flags buffer.
  154.  */
  155. #define TTY_NORMAL    0
  156. #define TTY_BREAK    1
  157. #define TTY_FRAME    2
  158. #define TTY_PARITY    3
  159. #define TTY_OVERRUN    4
  160.  
  161. #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
  162. #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
  163. #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
  164. #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
  165. #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
  166. #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME])
  167. #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN])
  168. #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC])
  169. #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
  170. #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
  171. #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
  172. #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL])
  173. #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT])
  174. #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD])
  175. #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE])
  176. #define LNEXT_CHAR(tty)    ((tty)->termios->c_cc[VLNEXT])
  177. #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2])
  178.  
  179. #define _I_FLAG(tty,f)    ((tty)->termios->c_iflag & (f))
  180. #define _O_FLAG(tty,f)    ((tty)->termios->c_oflag & (f))
  181. #define _C_FLAG(tty,f)    ((tty)->termios->c_cflag & (f))
  182. #define _L_FLAG(tty,f)    ((tty)->termios->c_lflag & (f))
  183.  
  184. #define I_IGNBRK(tty)    _I_FLAG((tty),IGNBRK)
  185. #define I_BRKINT(tty)    _I_FLAG((tty),BRKINT)
  186. #define I_IGNPAR(tty)    _I_FLAG((tty),IGNPAR)
  187. #define I_PARMRK(tty)    _I_FLAG((tty),PARMRK)
  188. #define I_INPCK(tty)    _I_FLAG((tty),INPCK)
  189. #define I_ISTRIP(tty)    _I_FLAG((tty),ISTRIP)
  190. #define I_INLCR(tty)    _I_FLAG((tty),INLCR)
  191. #define I_IGNCR(tty)    _I_FLAG((tty),IGNCR)
  192. #define I_ICRNL(tty)    _I_FLAG((tty),ICRNL)
  193. #define I_IUCLC(tty)    _I_FLAG((tty),IUCLC)
  194. #define I_IXON(tty)    _I_FLAG((tty),IXON)
  195. #define I_IXANY(tty)    _I_FLAG((tty),IXANY)
  196. #define I_IXOFF(tty)    _I_FLAG((tty),IXOFF)
  197. #define I_IMAXBEL(tty)    _I_FLAG((tty),IMAXBEL)
  198.  
  199. #define O_OPOST(tty)    _O_FLAG((tty),OPOST)
  200. #define O_OLCUC(tty)    _O_FLAG((tty),OLCUC)
  201. #define O_ONLCR(tty)    _O_FLAG((tty),ONLCR)
  202. #define O_OCRNL(tty)    _O_FLAG((tty),OCRNL)
  203. #define O_ONOCR(tty)    _O_FLAG((tty),ONOCR)
  204. #define O_ONLRET(tty)    _O_FLAG((tty),ONLRET)
  205. #define O_OFILL(tty)    _O_FLAG((tty),OFILL)
  206. #define O_OFDEL(tty)    _O_FLAG((tty),OFDEL)
  207. #define O_NLDLY(tty)    _O_FLAG((tty),NLDLY)
  208. #define O_CRDLY(tty)    _O_FLAG((tty),CRDLY)
  209. #define O_TABDLY(tty)    _O_FLAG((tty),TABDLY)
  210. #define O_BSDLY(tty)    _O_FLAG((tty),BSDLY)
  211. #define O_VTDLY(tty)    _O_FLAG((tty),VTDLY)
  212. #define O_FFDLY(tty)    _O_FLAG((tty),FFDLY)
  213.  
  214. #define C_BAUD(tty)    _C_FLAG((tty),CBAUD)
  215. #define C_CSIZE(tty)    _C_FLAG((tty),CSIZE)
  216. #define C_CSTOPB(tty)    _C_FLAG((tty),CSTOPB)
  217. #define C_CREAD(tty)    _C_FLAG((tty),CREAD)
  218. #define C_PARENB(tty)    _C_FLAG((tty),PARENB)
  219. #define C_PARODD(tty)    _C_FLAG((tty),PARODD)
  220. #define C_HUPCL(tty)    _C_FLAG((tty),HUPCL)
  221. #define C_CLOCAL(tty)    _C_FLAG((tty),CLOCAL)
  222. #define C_CIBAUD(tty)    _C_FLAG((tty),CIBAUD)
  223. #define C_CRTSCTS(tty)    _C_FLAG((tty),CRTSCTS)
  224.  
  225. #define L_ISIG(tty)    _L_FLAG((tty),ISIG)
  226. #define L_ICANON(tty)    _L_FLAG((tty),ICANON)
  227. #define L_XCASE(tty)    _L_FLAG((tty),XCASE)
  228. #define L_ECHO(tty)    _L_FLAG((tty),ECHO)
  229. #define L_ECHOE(tty)    _L_FLAG((tty),ECHOE)
  230. #define L_ECHOK(tty)    _L_FLAG((tty),ECHOK)
  231. #define L_ECHONL(tty)    _L_FLAG((tty),ECHONL)
  232. #define L_NOFLSH(tty)    _L_FLAG((tty),NOFLSH)
  233. #define L_TOSTOP(tty)    _L_FLAG((tty),TOSTOP)
  234. #define L_ECHOCTL(tty)    _L_FLAG((tty),ECHOCTL)
  235. #define L_ECHOPRT(tty)    _L_FLAG((tty),ECHOPRT)
  236. #define L_ECHOKE(tty)    _L_FLAG((tty),ECHOKE)
  237. #define L_FLUSHO(tty)    _L_FLAG((tty),FLUSHO)
  238. #define L_PENDIN(tty)    _L_FLAG((tty),PENDIN)
  239. #define L_IEXTEN(tty)    _L_FLAG((tty),IEXTEN)
  240.  
  241. /*
  242.  * Where all of the state associated with a tty is kept while the tty
  243.  * is open.  Since the termios state should be kept even if the tty
  244.  * has been closed --- for things like the baud rate, etc --- it is
  245.  * not stored here, but rather a pointer to the real state is stored
  246.  * here.  Possible the winsize structure should have the same
  247.  * treatment, but (1) the default 80x24 is usually right and (2) it's
  248.  * most often used by a windowing system, which will set the correct
  249.  * size each time the window is created or resized anyway.
  250.  * IMPORTANT: since this structure is dynamically allocated, it must
  251.  * be no larger than 4096 bytes.  Changing TTY_FLIPBUF_SIZE will change
  252.  * the size of this structure, and it needs to be done with care.
  253.  *                         - TYT, 9/14/92
  254.  */
  255. struct tty_struct {
  256.     int    magic;
  257.     struct tty_driver driver;
  258.     struct tty_ldisc ldisc;
  259.     struct termios *termios, *termios_locked;
  260.     int pgrp;
  261.     int session;
  262.     kdev_t    device;
  263.     unsigned long flags;
  264.     int count;
  265.     struct winsize winsize;
  266.     unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1;
  267.     unsigned char low_latency:1, warned:1;
  268.     unsigned char ctrl_status;
  269.  
  270.     struct tty_struct *link;
  271.     struct fasync_struct *fasync;
  272.     struct tty_flip_buffer flip;
  273.     int max_flip_cnt;
  274.     int alt_speed;        /* For magic substitution of 38400 bps */
  275.     struct wait_queue *write_wait;
  276.     struct wait_queue *read_wait;
  277.     struct tq_struct tq_hangup;
  278.     void *disc_data;
  279.     void *driver_data;
  280.  
  281. #define N_TTY_BUF_SIZE 4096
  282.     
  283.     /*
  284.      * The following is data for the N_TTY line discipline.  For
  285.      * historical reasons, this is included in the tty structure.
  286.      */
  287.     unsigned int column;
  288.     unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
  289.     unsigned char closing:1;
  290.     unsigned short minimum_to_wake;
  291.     unsigned overrun_time;
  292.     int num_overrun;
  293.     unsigned long process_char_map[256/(8*sizeof(unsigned long))];
  294.     char *read_buf;
  295.     int read_head;
  296.     int read_tail;
  297.     int read_cnt;
  298.     unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))];
  299.     int canon_data;
  300.     unsigned long canon_head;
  301.     unsigned int canon_column;
  302.     struct semaphore atomic_read;
  303. };
  304.  
  305. /* tty magic number */
  306. #define TTY_MAGIC        0x5401
  307.  
  308. /*
  309.  * These bits are used in the flags field of the tty structure.
  310.  * 
  311.  * So that interrupts won't be able to mess up the queues,
  312.  * copy_to_cooked must be atomic with respect to itself, as must
  313.  * tty->write.  Thus, you must use the inline functions set_bit() and
  314.  * clear_bit() to make things atomic.
  315.  */
  316. #define TTY_THROTTLED 0
  317. #define TTY_IO_ERROR 1
  318. #define TTY_OTHER_CLOSED 2
  319. #define TTY_EXCLUSIVE 3
  320. #define TTY_DEBUG 4
  321. #define TTY_DO_WRITE_WAKEUP 5
  322. #define TTY_PUSH 6
  323. #define TTY_CLOSING 7
  324. #define TTY_DONT_FLIP 8
  325. #define TTY_HW_COOK_OUT 14
  326. #define TTY_HW_COOK_IN 15
  327. #define TTY_PTY_LOCK 16
  328.  
  329. #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
  330.  
  331. extern void tty_write_flush(struct tty_struct *);
  332.  
  333. extern struct termios tty_std_termios;
  334. extern struct tty_struct * redirect;
  335. extern struct tty_ldisc ldiscs[];
  336. extern int fg_console, last_console, want_console;
  337.  
  338. extern int kmsg_redirect;
  339.  
  340. extern unsigned long con_init(unsigned long);
  341.  
  342. extern int rs_init(void);
  343. extern int lp_init(void);
  344. extern int pty_init(void);
  345. extern int tty_init(void);
  346. extern int pcxe_init(void);
  347. extern int pc_init(void);
  348. extern int vcs_init(void);
  349. extern int rp_init(void);
  350. extern int cy_init(void);
  351. extern int stl_init(void);
  352. extern int stli_init(void);
  353. extern int riscom8_init(void);
  354. extern int specialix_init(void);
  355. extern int espserial_init(void);
  356. extern int macserial_init(void);
  357.  
  358. extern int tty_paranoia_check(struct tty_struct *tty, kdev_t device,
  359.                   const char *routine);
  360. extern char *tty_name(struct tty_struct *tty, char *buf);
  361. extern void tty_wait_until_sent(struct tty_struct * tty, long timeout);
  362. extern int tty_check_change(struct tty_struct * tty);
  363. extern void stop_tty(struct tty_struct * tty);
  364. extern void start_tty(struct tty_struct * tty);
  365. extern int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc);
  366. extern int tty_register_driver(struct tty_driver *driver);
  367. extern int tty_unregister_driver(struct tty_driver *driver);
  368. extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
  369.                  int buflen);
  370. extern void tty_write_message(struct tty_struct *tty, char *msg);
  371.  
  372. extern int is_orphaned_pgrp(int pgrp);
  373. extern int is_ignored(int sig);
  374. extern int tty_signal(int sig, struct tty_struct *tty);
  375. extern void tty_hangup(struct tty_struct * tty);
  376. extern void tty_vhangup(struct tty_struct * tty);
  377. extern void tty_unhangup(struct file *filp);
  378. extern int tty_hung_up_p(struct file * filp);
  379. extern void do_SAK(struct tty_struct *tty);
  380. extern void disassociate_ctty(int priv);
  381. extern void tty_flip_buffer_push(struct tty_struct *tty);
  382. extern int tty_get_baud_rate(struct tty_struct *tty);
  383.  
  384. /* n_tty.c */
  385. extern struct tty_ldisc tty_ldisc_N_TTY;
  386.  
  387. /* tty_ioctl.c */
  388. extern int n_tty_ioctl(struct tty_struct * tty, struct file * file,
  389.                unsigned int cmd, unsigned long arg);
  390.  
  391. /* serial.c */
  392.  
  393. extern long serial_console_init(long kmem_start, long kmem_end);
  394.  
  395. /* pcxx.c */
  396.  
  397. extern int pcxe_open(struct tty_struct *tty, struct file *filp);
  398.  
  399. /* printk.c */
  400.  
  401. extern void console_print(const char *);
  402.  
  403. /* vt.c */
  404.  
  405. extern int vt_ioctl(struct tty_struct *tty, struct file * file,
  406.             unsigned int cmd, unsigned long arg);
  407.  
  408. #endif /* __KERNEL__ */
  409. #endif
  410.